﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mebc.tests.toDictionary
{
    class Split_into_assignments : Part
    {
        public Split_into_assignments()
        {
            Process<string>(config => Send<IEnumerable<string>>(config.Split(';')));
        }
    }

    class Transform_assignments_into_KV : FuncPart<IEnumerable<string>,IEnumerable<KeyValuePair<string,string>>>
    {
        public Transform_assignments_into_KV()
            : base(assignments => assignments.Select(a => a.Split('='))
                                             .Select(parts => new KeyValuePair<string, string>(parts[0], parts[1]))) {}
    }


    class Build_dictionary : FuncPart<IEnumerable<KeyValuePair<string,string>>, Dictionary<string,string>>
    {
        public Build_dictionary()
            : base(kvpairs => kvpairs.Aggregate(new Dictionary<string, string>(), 
                                                (dict, kvp) => { dict.Add(kvp.Key, kvp.Value); return dict; })) {}
    }
}
